package ir.values.users.instructions;

import ir.types.datatypes.DataType;
import ir.types.datatypes.IntegerType;
import ir.values.Value;

public class ZextInst extends Instruction {
    private final Value operand;
    public ZextInst(DataType targetType, Value operand) {
        super(null, targetType);
        this.operand = operand;
        operands.add(operand);
    }

    public ZextInst(Value operand) {
        this(IntegerType.I32, operand);
    }

    public DataType getDataType() {
        return (DataType) type;
    }

    @Override
    public String parseLLVM() {
        StringBuilder sb = new StringBuilder();
        sb
                .append(parseUsingName())
                .append(" = ")
                .append(getInstOperator())
                .append(" ")
                .append(operand.getType())
                .append(" ")
                .append(operand.parseUsingName())
                .append(" to ")
                .append(type);
        return sb.toString();
    }

    @Override
    public InstOperator getInstOperator() {
        return InstOperator.zext;
    }
}
